package cn.wen233.iocdemo.api;

import cn.wen233.iocdemo.application.service.Esp8266Service;
import cn.wen233.iocdemo.common.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制接口
 *
 * @author wenei
 * @date 2021-06-22 9:21
 */
@RestController
public class ControlApi {

    private final Esp8266Service esp8266Service;

    public ControlApi(Esp8266Service singleChipService) {
        this.esp8266Service = singleChipService;
    }

    @GetMapping("/dht11")
    public R<?> dht11() {
        return R.success(esp8266Service.dht11());
    }

    @GetMapping("/openLed")
    public R<?> openLed() {
        return R.success(esp8266Service.ledControl(true));
    }

    @GetMapping("/closeLed")
    public R<?> closeLed() {
        return R.success(esp8266Service.ledControl(false));
    }

    @GetMapping("/openMotor")
    public R<?> openMotor() {
        return R.success(esp8266Service.motorControl(true));
    }

    @GetMapping("/closeMotor")
    public R<?> closeMotor() {
        return R.success(esp8266Service.motorControl(false));
    }
}
